package com.bbt.dormassistant.controller;

import com.bbt.dormassistant.entity.UserInformation;
import com.bbt.dormassistant.service.UserInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "用户信息接口")
@RestController
@RequestMapping("/userInformation")
public class UserInformationController {

    @Autowired
    private UserInformationService userInformationService;

    @ApiOperation(value = "根据userID查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String"),
    })
    @PostMapping("/addUserInformation")
    public Map addUserInformation(@RequestParam(value = "userId") String userId
                                  ){
        Map<String, Object> map = new HashMap<>();
        UserInformation userInformation = new UserInformation();
        userInformation.setUserId(userId);
        map.put("success", userInformationService.addUserInformation(userInformation));

        return map;
    }


    @ApiOperation(value = "根据userID查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String")
    })
    @GetMapping("/queryUserInformationById")
    public Map queryUserInformationById(@RequestParam(value = "userId") String userId){
        Map<String,Object> map = new HashMap<>();
        map.put("user",userInformationService.queryUserInformationById(userId));
        return map;
    }


    @ApiOperation(value = "根据userID修改用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "name", value = "姓名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "nickName", value = "昵称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "gender", value = "性别(0:女，1:男)", required = true, dataType = "int"),
            @ApiImplicitParam(name = "number", value = "学号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "department", value = "专业", required = true, dataType = "String"),
            @ApiImplicitParam(name = "hobby", value = "兴趣", required = true, dataType = "String"),
            @ApiImplicitParam(name = "building", value = "宿舍楼栋", required = true, dataType = "String"),
            @ApiImplicitParam(name = "room", value = "房间号", required = true, dataType = "int"),
            @ApiImplicitParam(name = "wakeTime", value = "起床时间(例：8:30 )", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sleepTime", value = "睡觉时间(例：23:30)", required = true, dataType = "String"),
            @ApiImplicitParam(name = "avatarUrl", value = "头像地址", required = true, dataType = "String")
    })
    @PostMapping("/modifyUserInformation")
    public Map modifyUserInformation(@RequestParam(value = "userId") String userId,
                                                    @RequestParam(value = "name") String name,
                                                    @RequestParam(value = "nickName") String nickName,
                                                    @RequestParam(value = "gender") Integer gender,
                                                    @RequestParam(value = "number") String number,
                                                    @RequestParam(value = "department") String department,
                                                    @RequestParam(value = "hobby") String hobby,
                                                    @RequestParam(value = "building") String building,
                                                    @RequestParam(value = "room") Integer room,
                                                    @RequestParam(value = "wakeTime")String wakeTime,
                                                    @RequestParam(value = "sleepTime") String sleepTime,
                                                    @RequestParam(value = "avatarUrl") String avatarUrl){
        Map<String,Object> map  = new HashMap<>();
        map.put("success",userInformationService.modifyUserInformation(userId,name,nickName,gender,number,department,hobby,building,room,wakeTime,sleepTime,avatarUrl));
        return map;
    }



    @ApiOperation(value = "查询所有用户信息")
    @GetMapping("/queryAllUserInformation")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currIndex", value = "当前页码(可选项)", required = false, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页大小(可选项)", required = false, dataType = "int")
    })
    public Map queryAllUserInformation(@RequestParam(value = "currIndex",required = false) Integer currIndex,
                                       @RequestParam(value = "pageSize",required = false) Integer pageSize){
        Map<String,Object> map  = new HashMap<>();
        map.put("users",userInformationService.queryAllUserInformations(currIndex,pageSize));
        return map;
    }






}
